package dao.oc_station;

import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import entitybean.oc_station.EntityBeanOc_Station;

public class DaoImpl_Oc_Station  extends HibernateDaoSupport implements Dao_Oc_Station{
	public void Insert_Oc_Station(EntityBeanOc_Station e)
	{
		this.getHibernateTemplate().save(e);
	}
	public void Update_Oc_Station(EntityBeanOc_Station e)
	{
		this.getHibernateTemplate().update(e);
	}
	public void Delete_Oc_Station(EntityBeanOc_Station e)
	{
		this.getHibernateTemplate().delete(e);
	}
	@SuppressWarnings("unchecked")
	public List<EntityBeanOc_Station> Find_Oc_Station_by_oc_voyage_id(Integer id,Integer j)
	{
		return this.getHibernateTemplate().find("from EntityBeanOc_Station where del='OFF' and territorial_waters="+j+"  and oc_voyage_id="+id);
	}
	@SuppressWarnings("unchecked")
	public List<EntityBeanOc_Station> Find_Oc_Station_by_oc_voyage_id(Integer id)
	{
		return this.getHibernateTemplate().find("from EntityBeanOc_Station where del='OFF' and oc_voyage_id="+id);
	}
	@SuppressWarnings("unchecked")
	public EntityBeanOc_Station Find_Oc_Station_by_oc_id(Integer id)
	{
		EntityBeanOc_Station e= new EntityBeanOc_Station();
		List<EntityBeanOc_Station> list=this.getHibernateTemplate().find("from EntityBeanOc_Station where del='OFF' and id="+id);
		if(list.size()>0)
		{
			e=list.get(0);
		}
		return e;
	}
	@SuppressWarnings("unchecked")
	public EntityBeanOc_Station Find_Oc_Station_by_L_D(String L,String D,String voyage)
	{
		EntityBeanOc_Station e= new EntityBeanOc_Station();
		List<EntityBeanOc_Station> list=this.getHibernateTemplate().find("from EntityBeanOc_Station where del='OFF' " +
				"and oc_voyage_id="+voyage+" and longitude='"+L+"' AND dimensionality='"+D+"'");
		if(list.size()>0)
		{
			e=list.get(0);
		}
		return e;
		
	}
	@SuppressWarnings("unchecked")
	public void Delete_Oc_Station(String id)
	{
		List<EntityBeanOc_Station> list=this.getHibernateTemplate().find("from EntityBeanOc_Station where del='OFF' and id in("+id+")");	
		for(int i=0;i<list.size();i++)
		{
			EntityBeanOc_Station e=list.get(i);
			/*System.out.println("e.getCtd()="+e.getCtd());
			System.out.println("e.getDel()="+e.getDel());
			System.out.println("e.getDepth()="+e.getDepth());
			System.out.println("e.getDimensionality()="+e.getDimensionality());
			System.out.println("e.getLongitude()="+e.getLongitude());
			System.out.println("e.getStation_name()="+e.getStation_name());
			System.out.println("e.getId()="+e.getId());
			System.out.println("e.getOc_voyage_id()="+e.getOc_voyage_id());
			System.out.println("e.getTerritorial_waters()="+e.getTerritorial_waters());*/
			e.setDel("ON");
			
			this.getHibernateTemplate().update(e);
		
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<EntityBeanOc_Station> Find_Oc_Station_is_active()
	{
		
		return this.getHibernateTemplate().find("from EntityBeanOc_Station where del='OFF'");
		
	}
}
